package org.txazo.common.util;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Test1 {

	private static byte[] request = null;

	static {
		StringBuffer temp = new StringBuffer();
		temp.append("GET http://nitrome.com.4399.com:8080/4399swf/upload_swf/ftp5/haibo/20110709/1/game.swf HTTP/1.1\r\n");
		temp.append("Host: nitrome.com.4399.com:8080\r\n");
		temp.append("Connection: keep-alive\r\n");
		temp.append("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
		temp.append("User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36\r\n");
		temp.append("Accept-Encoding: gzip,deflate,sdch\r\n");
		temp.append("Accept-Language: zh-CN,zh;q=0.8\r\n");
		temp.append("\r\n");
		request = temp.toString().getBytes();
	}

	public static void sendHttpRequest() throws Exception {
		Socket socket = new Socket("202.96.140.13", 8080);

		OutputStream os = socket.getOutputStream();
		os.write(request);
		os.flush();

		InputStream is = socket.getInputStream();
		FileOutputStream fos = new FileOutputStream("D:/1122.swf");
		int length = -1;
		byte[] temp = new byte[4096];

		while ((length = is.read(temp)) != -1) {
			fos.write(temp, 0, length);
		}

		fos.close();
		is.close();

		os.close();
		socket.close();
	}

	public static void main(String[] args) throws Exception {
		sendHttpRequest();
	}

}
